<?php
/**
 * Created by PhpStorm.
 * User: leo
 * Date: 2018/5/20
 * Time: 1:26
 */
include "../classes/logincheck.php";
include('../classes/conn.php');
$class=$_POST['class'];
if(islogin()!="teacher_login"){
    die('error');
}
$name1=$_FILES['file']['name'];
$name=iconv("UTF-8","GB2312",$_FILES['file']['name']);
$name=$class.$name;
$dir="../Files/". $_SESSION['t_num'] . "/shared/" . $name;

if(file_exists($dir)){
    die('file_exist');
}

move_uploaded_file($_FILES['file']['tmp_name'],$dir);

$dir="requests/Files/". $_SESSION['t_num'] . "/shared/" . $class.$name1;

$query="insert into sharedfile (name, path, class) VALUES ('{$name1}','{$dir}','{$class}')";
$res=mysql_query($query);
if($res){
    echo '1';
}
else echo '0';